package com.ktgj.flight.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.flight.domain.Airport;
import com.ktgj.flight.domain.vo.ChannelListVo;
import com.ktgj.flight.task.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.flight.domain.Airliner;
import com.ktgj.flight.service.IAirlinerService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 航空公司Controller
 *
 * @author ruoyi
 * @date 2021-08-30
 */
@ControllerAdvice
@RestController
@RequestMapping("/airliner")
public class AirlinerController extends BaseController {
    @Autowired
    private IAirlinerService airlinerService;

    /**
     * 查询航空公司列表
     */
    //@PreAuthorize(hasPermi = "flight:airliner:list")
    @PostMapping("/list")
    public AjaxResult list(Airliner airliner) {
        List<Airliner> list = airlinerService.selectAirlinerList(airliner);
        return AjaxResult.success(list);
    }

    /**
     * CRM查询航空公司列表
     *
     * @param airliner
     * @return
     */
    @PostMapping("/airportList")
    public TableDataInfo airportList(@RequestBody Airliner airliner) {
        startPage();
        List<Airliner> airliners = airlinerService.selectAirlinerList(airliner);
        return getDataTable(airliners);
    }

    /**
     * 导出航空公司列表
     */
    @PreAuthorize(hasPermi = "flight:airliner:export")
    @Log(title = "航空公司", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Airliner airliner) throws IOException {
        List<Airliner> list = airlinerService.selectAirlinerList(airliner);
        ExcelUtil<Airliner> util = new ExcelUtil<Airliner>(Airliner.class);
        util.exportExcel(response, list, "航空公司数据");
    }

    /**
     * 获取航空公司详细信息
     */
    //@PreAuthorize(hasPermi = "flight:airliner:query")
    @PostMapping("/getInfo")
    public AjaxResult getInfo(@RequestBody Map<String, Object> map) {
        Long id = Long.valueOf(map.get("id").toString());
        return AjaxResult.success(airlinerService.selectAirlinerById(id));
    }

    /**
     * 新增航空公司
     */
    //@PreAuthorize(hasPermi = "flight:airliner:add")
    @Log(title = "航空公司", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Airliner airliner) {
        return toAjax(airlinerService.insertAirliner(airliner));
    }

    /**
     * 修改航空公司
     */
    //@PreAuthorize(hasPermi = "flight:airliner:edit")
    @Log(title = "航空公司", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody Airliner airliner) {
        return toAjax(airlinerService.updateAirliner(airliner));
    }

    /**
     * 删除航空公司
     *
     * @param map
     * @return
     */
    @PostMapping("/deleteAirLinerById")
    public AjaxResult deleteAirLinerById(@RequestBody Map<String, Object> map) {
        Long id = Long.valueOf(map.get("id").toString());
        return toAjax(airlinerService.deleteAirLinerById(id));
    }

    /**
     * 删除航空公司
     */
    //@PreAuthorize(hasPermi = "flight:airliner:remove")
    @Log(title = "航空公司", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(airlinerService.deleteAirlinerByIds(ids));
    }

    /**
     * 远程调用
     *
     * @param airlinerId
     * @return
     */
    @PostMapping("/queryAirlinerByAirlinerId")
    public String queryAirlinerByAirlinerId(@RequestParam("airlinerId") String airlinerId) {
        String airliner = airlinerService.queryAirlinerByAirlinerId(airlinerId);
        return airliner;
    }

    /**
     * 航司下拉框数据
     */
    @PostMapping("/queryAirlinerSelect")
    public AjaxResult queryAirlinerSelect(){
        return AjaxResult.success(airlinerService.queryAirlinerSelect());
    }

    /**
     * 原始账单查询报表渠道列表
     * */
    @PostMapping("/channelList")
    public AjaxResult channelList(){
        List<ChannelListVo> channelListVoList = airlinerService.channelList();
        return AjaxResult.success(channelListVoList);
    }

    /**
     * 代码获取航司名（远程）
     * */
    @PostMapping("/airlinerName")
    public String airlinerName(@RequestBody Map<String, Object> map){
        String card = map.get("card").toString();
        String name = airlinerService.airlinerName(card);
        return name;
    }

//    @PostMapping("/d")
//    public AjaxResult d(){
//        Scheduler scheduler = new Scheduler();
//        scheduler.QMsgSC();
//        return AjaxResult.success("1");
//    }
}
